package com.mes.sync;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.mes.entity.Message;
import com.mes.entity.MessageLog;
import com.mes.service.MessageService;
import com.mes.utils.SendMessageUtil;

public class MessageSendUtil {
	@Autowired
	private MessageService service;
	
	public void sendMessage() {
		try {
			List<Message> list = service.getMessageList();
			MessageLog log = null;
			System.out.println("!!!!!!!!!");
			for(Message msg : list) {
				try {
					SendMessageUtil.sendMessage(msg.getPhone(), msg.getUserName(), msg.getText());
					
					log = new MessageLog();
					log.setAddress(msg.getPhone());
					log.setMessageId(msg.getMessageId());
					log.setUserId(msg.getUserId());
					
					service.addMessageLog(log);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}